package com.sunyu.springboot.controller;

import com.power.common.model.CommonResult;
import com.sunyu.springboot.component.RestTemplateClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.net.InetAddress;

/**
 * @author yu 2018/12/21.
 */
@RestController
public class HttpTestController {


    @Resource
    private RestTemplateClient restTemplateClient;

    /**
     * 测试https
     * @return
     */
    @GetMapping("testHttps")
    public CommonResult<String> testHttps() {
        String url = "https://www.baidu.com/";
        String result = restTemplateClient.getForObject(url, String.class);
        return CommonResult.ok().setResult(result);
    }

    /**
     * 测试http
     * @return
     * @throws Exception
     */
    @GetMapping("testHttp")
    public CommonResult<String> testHttp() throws Exception {
        InetAddress addr = InetAddress.getLocalHost();
        String ip = addr.getHostAddress().toString();
        String url = String.format("http://%s:8080/",ip);
        String result = restTemplateClient.getForObject(url, String.class);
        return CommonResult.ok().setResult(result);
    }
}
